#include <iostream>
#include <queue>

int n, m;

int gcd(int a, int b)
{
	return (b == 0) ? a : gcd(b, a % b);
}

int main()
{
	while (std::cin >> n >> m) {
		int t = gcd(n, m);
		n /= t;  m /= t;
		int ca = 0, cb = 0;
		for (; !(n % 2); n /= 2) ca++;
		for (; !(m % 2); m /= 2) cb++;

		for (; !(n % 3); n /= 3) ca++;
		for (; !(m % 3); m /= 3) cb++;

		for (; !(n % 5); n /= 5) ca++;
		for (; !(m % 5); m /= 5) cb++;

		if (!(n == 1 && m == 1)) {
			std::cout << "-1\n";
		} else {
			std::cout << ca + cb << '\n';
		}
	}
}
